package com.bigger.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
@Order(1)//order注解中的值越小，执行优先级越高
public class GatewayFilter implements GlobalFilter {
    //用法和interceptor差不多（有需要进行相关的网关验证自行增加）
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //ServerHttpRequest request = exchange.getRequest();//获取请求request对象（可获取请求的请求头，请求参数等）
        //ServerHttpResponse response = exchange.getResponse(); //获取响应response对象（可在响应中添加一些信息和设置响应状态码）
        //return exchange.getResponse().setComplete();//拦截请求
        return chain.filter(exchange);//放行请求
    }
}
